//package com.waiting.https;
//
//import org.apache.http.HttpEntity;
//import org.apache.http.NameValuePair;
//import org.apache.http.client.config.RequestConfig;
//import org.apache.http.client.entity.UrlEncodedFormEntity;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
//import org.apache.http.conn.ssl.SSLContextBuilder;
//import org.apache.http.conn.ssl.TrustStrategy;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.message.BasicNameValuePair;
//import org.apache.http.util.EntityUtils;
//import org.slf4j.MDC;
//
//import javax.net.ssl.SSLContext;
//import java.io.IOException;
//import java.security.KeyManagementException;
//import java.security.KeyStoreException;
//import java.security.NoSuchAlgorithmException;
//import java.security.cert.CertificateException;
//import java.security.cert.X509Certificate;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//
///**
// * @Description
// * @Author bjweitingting
// * @Date 2019/1/18
// **/
//public class HttpsClientDemo {
//    public static String sendPostSSL(String url, Map<String, String> parameterMap, int connectTimeout, int readTimeout, String encoding){
//        String content = null;
//        // 创建默认的httpClient实例.
//        CloseableHttpClient httpclient = createSSLClientDefault();
//        // 创建httppost
//        HttpPost httppost = new HttpPost(url);
//        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(connectTimeout).setConnectTimeout(readTimeout).build();//设置请求和传输超时时间
//        httppost.setConfig(requestConfig);
//        FullLinkUtil.addParam2HttpHeader(httppost, (String)MDC.get(ConstantTraceLogBean.TRACE_ID), (String)MDC.get(THREADLOCAL_SPANID));
//        // 创建参数队列
//        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
//        Set<Map.Entry<String,String>> set = parameterMap.entrySet();
//        for(Map.Entry<String,String> entry : set){
//            formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
//        }
//        UrlEncodedFormEntity uefEntity;
//        try {
//            uefEntity = new UrlEncodedFormEntity(formparams, encoding);
//            httppost.setEntity(uefEntity);
//            CloseableHttpResponse response = httpclient.execute(httppost);
//            try {
//                HttpEntity entity = response.getEntity();
//                if (entity != null) {
//                    content =  EntityUtils.toString(entity, encoding);
//                }
//            } finally {
//                response.close();
//            }
//        } catch (Exception e) {
//           e.printStackTrace();
//        } finally {
//            // 关闭连接,释放资源
//            try {
//                httpclient.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return content;
//    }
//
//    public static CloseableHttpClient createSSLClientDefault(){
//        SSLContext sslContext = null;
//        try {
//            sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
//                //信任所有
//                public boolean isTrusted(X509Certificate[] chain,
//                                         String authType) throws CertificateException {
//                    return true;
//                }
//            }).build();
//        } catch (NoSuchAlgorithmException e) {
//            e.printStackTrace();
//        } catch (KeyManagementException e) {
//            e.printStackTrace();
//        } catch (KeyStoreException e) {
//            e.printStackTrace();
//        }
//        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
//        return HttpClients.custom().setSSLSocketFactory(sslsf).build();
//    }
//}
